// FrogExtractFolderDialog.cpp : Implementation of CFrogExtractFolderDialog

#include "stdafx.h"
#include "FrogExtractFolderDialog.h"
#include "FrogMessageBox.h"

// CFrogExtractFolderDialog
CFrogExtractFolderDialog::CFrogExtractFolderDialog(HICON hIcon):
CFrogProgressReportDialog(hIcon),
m_FolderName(L"FolderName")
{
}

LRESULT CFrogExtractFolderDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CFrogProgressReportDialog::OnInitDialog(uMsg, wParam, lParam, bHandled);
	DoDataExchange(FALSE);

	CEdit editFolder;
	editFolder.Attach(GetDlgItem(IDC_EDIT_FOLDER));
	editFolder.SetSel(0, -1);
	editFolder.SetFocus();

	return 0;
}

LRESULT CFrogExtractFolderDialog::OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	bHandled = TRUE;
	// TODO: Add your control notification handler code here

	DoDataExchange(TRUE);

	if (m_FolderName == L"")
	{
		FrogMessageBox(m_hWnd, L"Cannot Enter Empty Folder Name", L"Folder Name Validation", 0);
		return TRUE;
	}

	if (!FilerFrogUtils::IsFileNameValid(wstring(m_FolderName)))
	{
		FrogMessageBox(m_hWnd, L"A folder name cannot contain any of the following characters:\n\\ / : * ? \" < > |", L"Folder Name Validation", 0);
		return TRUE;
	}

	RunAsyncCommandWithProgressBar();

	EndDialog(wID);
	return 0;
}

void CFrogExtractFolderDialog::ExecuteCommand()
{
	m_FilesRefactor.ExtractFilesToFolder(m_LastResult, m_FilesList, m_FolderPath, wstring(m_FolderName));
}